//
//  ym_OderButton.m
//  YiMiao
//
//  Created by apple on 15/11/27.
//  Copyright © 2015年 yimiao.tm. All rights reserved.
//

#import "ym_OderButton.h"
#import "UIImage+MJ.h"
@implementation ym_OderButton
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.hidden = NO;
        self.userInteractionEnabled = NO;
        self.titleLabel.font = [UIFont systemFontOfSize:9];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage resizedImageWithName:@"numberorder"] forState:UIControlStateNormal];
    }
    
    return self;
}

-(void)setBadgeValue:(NSString *)badgeValue
{
    _badgeValue = badgeValue;
    
    if ([self.badgeValue intValue] == 0) {
        // 没有值
        self.hidden = YES;
    } else {
        self.hidden = NO;
        
        [self setTitle:badgeValue forState:UIControlStateNormal];
        
        CGFloat badgeButtonH = self.currentBackgroundImage.size.height;
        
        CGFloat badgeButtonW = self.currentBackgroundImage.size.width;
        if (badgeValue.length > 1) {
            badgeButtonW = [badgeValue sizeWithFont:self.titleLabel.font].width+10;
            
        }
        
        self.frame = CGRectMake(0, 0, badgeButtonW, badgeButtonH);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
